<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple
*/
//获取访问入口
$in=dirname(__FILE__);
$in=str_replace(dirname($in),'',$in);
$in=substr($in,1);
define('IN',$in);
require_once '../core/core.php';
//其他站点一键登录
if($_GET['apikey'] && $_GET['timestamp'] && $_GET['sign']){
	$time=$_GET['timestamp'];
	if($time && ((TIMESTAMP+600) >$time) && (TIMESTAMP-$time)<600){
		$site=pdo_get('core_accounts',array('token'=>trim($_GET['apikey'])),array('uniacid','aeskey'));
		$site['type']=pdo_getcolumn('core_users',array('id'=>$site['uniacid']),'type');
		$site['secret']=$site['aeskey'];
		$url=manage_url('core/app_release.myshop.plugins//isapi=1',true);
		if($site){
			$sign=$_GET['sign'];
			unset($_GET['sign']);
			$check_sign=get_sign($_GET,$site['secret']);
			if($check_sign == $sign){
				if($site['uniacid']==1 || $site['type']!=3){
					exi('只允许普通用户通过第三方登录！','error');
				}
				model('core/user')->login($site['uniacid']);
				if($_GET['url']){
					$_GET['url']=base64_decode($_GET['url']);
					$url=manage_url($_GET['url'],true);
				}
				header('Location:'.$url);
			}
		}else{
			exi('密钥错误,自动登录失败！','error',$url);
		}
	}
}
if($_SESSION['this']=='custom'){
	$_SESSION['this']=$in;
}
//域名检测。系统分配给站点的独立域名不允许访问后台。
if(USER_DOMAIN && strexists($_SERVER['HTTP_HOST'],USER_DOMAIN)){
	//非法域名直接退出
	exit;
}
//第三方平台登陆代码
if($_RQ['plugin']=='core' && $_RQ['action']=='open_login'){
	require 'open_login.php';
	exit;
}
//企业微信平台登陆代码
if($_RQ['action']=='basic.module_home' && ($_RQ['op']=='qyopen_set' || $_RQ['op']=='qyopen_index')){
	if($_RQ['auth_code']){
		$content=model('core/wxwork_api')->get_login_info($_RQ['auth_code']);
		$_SESSION['uniacid']=pdo_getcolumn('core_open_user',array('open_uid'=>$content['corp_info']['corpid']),'uniacid');
		cfc('user')->login($_SESSION['uniacid']);
	}
}
//第三方插件入口
if(($_RQ['c'] && $_RQ['a']) || ($_RQ['action']=='module' && $_RQ['a']=='display')){
	$_RQ=model('core/openapi_web')->up_access($_RQ);
}
$_SESSION['fromh5wxapp']=$_RQ['fromh5wxapp']?intval($_RQ['fromh5wxapp']):$_SESSION['fromh5wxapp'];
$_SESSION['fromh5ttapp']=$_RQ['fromh5ttapp']?intval($_RQ['fromh5ttapp']):$_SESSION['fromh5ttapp'];
if($_RQ['fromh5wxapp']){
	$_SESSION['os']='mobile';
}
//借用
//开启借用系统公众号授权获取粉丝信息
if($_SESSION['uniacid'] && !$_SESSION['wechat_id'] && !$_SESSION['auth_wxid']){
	$_AR['wx']=pdo_get('core_account_wechat',array('uniacid'=>$_SESSION['uniacid'],'isdefault'=>1),array('id','appid','appsecret','type','oldid','is_open'));
	if(!$_AR['wx']){
		$_AR['wx']=pdo_get('core_account_wechat',array('uniacid'=>$_SESSION['uniacid']),array('id','appid','appsecret','type','oldid','is_open'));
	}
	$uni_auth=uni_setting('wechat_auth');
	$core_auth=core_setting('wechat_auth');
	if(!$core_auth['wechat_id']){
		$core_auth['wechat_id']=pdo_getcolumn('core_account_wechat',array('uniacid'=>1,'isdefault'=>1),'id');
		if(!$core_auth['wechat_id']){
			$core_auth['wechat_id']=pdo_getcolumn('core_account_wechat',array('uniacid'=>1),'id');
		}
	}
	if($core_auth['wechat_id'] && $_AR['wx']['type']!=4 && $_AR['wx']['is_open'] && $core_auth['open'] ==1){
		$_SESSION['auth_wxid']=$core_auth['wechat_id'];
	}else{
		$_SESSION['auth_wxid']=0;
	}
}
if(!$_SESSION['login_error']){
	if($_SESSION['container']=='wxapp' && $_RQ['wxgid']){
		require 'wxapp.php';
	}else if($_SESSION['container']=='wechat'){
		require 'wechat.php';
	}else if($_SESSION['container']=='aliapp' || $_SESSION['container']=='alipay'){
		require 'aliapp.php';
	}else if($_SESSION['container']=='baiduapp'){
		require 'baiduapp.php';
	}else if($_SESSION['container']=='ttapp'){
		require 'ttapp.php';
	}
}

if($_RQ['fromuser']){
	$_SESSION['fromuser']=intval($_RQ['fromuser']);
}
if((!$_RQ['plugin'] || $_RQ['plugin']=='core') && $_RQ['action']=='module'){
	if(!$_SESSION['uid']){
		header('Location:./index.php');
	}
	if(!$_RQ['m']){
		exit('参数错误，访问插件页面未指定插件。');
	}
	$need=pdo_getcolumn('core_old_plugins',array('name'=>$_RQ['m']),'need_menu');
	if(!$need || $_RQ['submit'] || POST){
		require ROOT_D.'/api/open_jyapi/index.php';
		exit;
	}
	$access=array('plugin'=>$_RQ['m'],'action'=>'','html'=>'../api.php?this=manage&'.$_SERVER['QUERY_STRING']);
}
if(!$access && $_RQ['plugin'] && $_RQ['action']){
	$access=array('plugin'=>$_RQ['plugin'],'action'=>$_RQ['action']);
	$access['op']=$_GET['op'];
}
if($_SESSION['account']['groupid']){
	$group=pdo_get('core_account_group',array('id'=>$_SESSION['account']['groupid']),array('index_url','plugin_name'));
	//移动模式下不自动跳转
	if(!$access && $group['index_url'] && $_SESSION['os']!='mobile'){
		$access=links($group['index_url']);
	}
	if($group['plugin_name'] && $_SESSION['current_plugin']!=$group['plugin_name']){
		$_SESSION['current_plugin']=$group['plugin_name'];
	}
}
//整理 access
if(!$access){
	$access=array();
	if($_RQ['action']){
		$action=$_RQ['action'];
	}elseif($_SESSION['access']['action']){
		$action=$_SESSION['access']['action'];
	}else{
		//这里改为登陆成功后显示首页，不进后台
		if(!$_SESSION['uid']){
				if($_AR['system']['home']){
					$action='home.welcome';
				}else{
					$action='user.login';
				}
		}else{			
			$user=pdo_get('core_users',array('id'=>$_SESSION['uid']),array('group_id','home'));
			if($user['home'] && $_SESSION['os']!='mobile'){
				$url=links($user['home']);
				$_RQ['plugin']=$url['plugin'];
				$action=$url['action'];
			}elseif($user['group_id'] && $_SESSION['os']!='mobile'){
				$welcome=pdo_getcolumn('core_user_groups',array('id'=>$user['group_id']),'welcome');
				if($welcome){
					$welcome=links($welcome);
					$_RQ['plugin']=$welcome['plugin'];
					$action=$welcome['action'];
					$_RQ['op']=$welcome['op'];
				}
			}
			if(!$action){
				$action='home.welcome';
				/*if($_AR['system']['istakeover'] && $_AR['system']['takeoverplugin']){
					$_RQ['plugin'] = $_AR['system']['takeoverplugin'];
					$action='index';
				}else{
					$action='account.welcome';
				}*/
			}
			if(!$_AR['system']['home'] && $action=='home.welcome'){
				$action='account.welcome';
			}
		}
	}
	$access['action']=$action;
	if($_RQ['plugin']){
		$plugin=$_RQ['plugin'];
	}elseif($_GET['action']){
		$plugin='core';
	}elseif($_SESSION['access']['plugin']){
		$plugin=$_SESSION['access']['plugin'];
	}else{
		$plugin='core';
	}
	$access['plugin']=$plugin;
	$access['op']=$_GET['op'];
	
}
//get参数
	if($_GET['plugin']){
		unset($_GET['plugin']);
	}
	if($_GET['action']){
		unset($_GET['action']);
	}
	unset($_GET['op']);
	if($_GET){
		$query=http_build_query($_GET);
	}elseif($_SESSION['access']['query'] && !$_RQ['action']){
		$query=$_SESSION['access']['query'];
	}
	if($query){
		$access['query']=$query;
	}

//整理 main_data
$main_data=array(
	'account'=>$_SESSION['account'],
	'isfounder'=>$_SESSION['isfounder'],
);
$_AR['page']=core_setting('site');
if($_AR['system']['no_app']){
	$main_data['no_app']=1;
}
$_AR['page']['name']=$_AR['page']['name']?:'进云智能';
$_AR['page']['title']=$_AR['page']['title'] ? $_AR['page']['title']:'进云智能快速开发系统，是一款免费开源的互联网产品开发管理系统！';
$_AR['page']['keywords']=$_AR['page']['keywords']? $_AR['page']['keywords']:'进云系统,微信公众号,手机移动开发,互联网+,模块开发,插件开发';
$_AR['page']['description']=$_AR['page']['description']? $_AR['page']['description']:'进云智能快速开发系统，是一款免费开源的互联网产品开发管理系统，是国内最完善移动网站及移动互联网技术解决方案！';
$_AR['page']['icon']=$_AR['page']['icon']?tomedia($_AR['page']['icon']):'../core/resource/images/logoicon.png';
$_AR['page']['mglogo']=$_AR['page']['mglogo']?tomedia($_AR['page']['mglogo']):'../core/resource/images/mg-logo.png';
$_AR['page']['logo']=$_AR['page']['logo']?tomedia($_AR['page']['logo']):'../core/resource/images/top-logo.png';
$_AR['page']['llogo']=$_AR['page']['llogo']?tomedia($_AR['page']['llogo']):'../core/resource/images/ng-logo.png';
$_AR['page']['js_supportimg']=tomedia($_AR['page']['js_supportimg']);
$_AR['page']['js_support']=$_AR['page']['js_support']?$_AR['page']['js_support']:'xx';
if(get_access_setting($_RQ['plugin'],$_RQ['action']) || IS_ROBOT){
  	//普通访问，此处整理生成页面
	access(array('plugin'=>$_RQ['plugin'],'action'=>$_RQ['action']));
	exit;
}
if($_SESSION['uid']){
	//获取系统菜单
	$framess=core_setting('menu');
	if(!$_AR['page']['plugin_menu']){
		//如果没有关闭扩展功能显示，则读取扩展功能菜单
		$childs=get_plugin_intypes();
		foreach($childs as &$child){
			$child=array('title'=>$child,'child'=>array());
		}
		$plugin_menu=array(
			'title'=>'站点应用_Industry app',
			'url'=>array('plugin'=>'core','action'=>'home.plugin_home','op'=>'get','query'=>'nolegao=0','title'=>'场景应用_Industry app'),
			'fa'=>'icon-yingyongbao',
			'legao_app'=>1,
			'child'=>$childs,
		);
		$plugins=pdo_getall('core_plugins',array('hide'=>0,'is_legao'=>1),array('name','title','style','intype'),'','star desc,paixu desc,id desc');
		foreach($plugins as $row){
			$plugin_menu['child'][$row['intype']]['child'][]=array('url'=>array('plugin'=>$row['name'],'action'=>'basic.module_home'),'title'=>$row['title']);
		}
		$plugin_menu['child']=array_values($plugin_menu['child']);
		$legao_app=$plugin_menu;
		$framess[]=$plugin_menu;
		//其他应用
		//兼容插件
		if($access['ismodule']==1){
			$api_modulemenus=model('core/template')->get_modulemenus($access['plugin']);
			if($api_modulemenus){
				$childs=$api_modulemenus;
			}
		}
		if(!$api_modulemenus){
			$childs=get_plugin_styles();
			foreach($childs as &$child){
				$child=array('title'=>$child,'child'=>array());
			}
		}
		$plugin_menu=array(
			'title'=>'其他应用_Other app',
			'url'=>array('plugin'=>'core','action'=>'home.plugin_home','op'=>'other','query'=>'nolegao=1','title'=>'其他应用_Other app'),
			'fa'=>'icon-similarproduct',
			'other_app'=>1,
			'child'=>$childs,
		);
		if(!$api_modulemenus){
			$plugins=pdo_getall('core_plugins',array('hide'=>0,'is_legao'=>0),array('name','title','style'),'','star desc,paixu desc,id desc');
			foreach($plugins as $row){
				$plugin_menu['child'][$row['style']]['child'][]=array('url'=>array('plugin'=>$row['name'],'action'=>'basic.module_home'),'title'=>$row['title']);
			}
		}
		$plugin_menu['child']=array_values($plugin_menu['child']);
		$other_app=$plugin_menu;
		$framess[]=$plugin_menu;
	}
	
	//整理菜单，删掉无权访问按钮，和隐藏的按钮。注意：系统菜单按钮和系统权限集并非完全一致。因此需要调用权限判断函数判断权限
	foreach($framess as $key1=>&$menu){
		if($menu['url']['plugin']=='core' && $menu['url']['action']=='basic.welcome' && strpos($_SESSION['account']['noshow_mainmenus'],';siteapp;') !== false){
			unset($framess[$key1]);
			continue;
		}
		if($menu['url']['plugin']=='core' && $menu['url']['action']=='basic.xiu_data' && strpos($_SESSION['account']['noshow_mainmenus'],';sitexiu;') !== false){
			unset($framess[$key1]);
			continue;
		}
		if($menu['url']['plugin']=='jy_weishop' && $menu['url']['action']=='basic.module_home' && strpos($_SESSION['account']['noshow_mainmenus'],';siteshop;') !== false){
			unset($framess[$key1]);
			continue;
		}
		if($menu['url']['plugin']=='core' && $menu['url']['action']=='wxwork.welcome' && strpos($_SESSION['account']['noshow_mainmenus'],';sitework;') !== false){
			unset($framess[$key1]);
			continue;
		}
		if($menu['hide']){
			unset($framess[$key1]);
			continue;
		}
		foreach($menu['child'] as $key2=>&$sub){
			if($sub['hide']){
				unset($menu['child'][$key2]);
				continue;
			}
			if($sub['title']=='小程序_wxapp' && strpos($_SESSION['account']['noshow_app'],';wxapp;') !== false){
				unset($menu['child'][$key2]);
				
				continue;
			}
			if($sub['title']=='微官网_h5web' && strpos($_SESSION['account']['noshow_app'],';mobile;') !== false){
				unset($menu['child'][$key2]);
				continue;
			}
			if($sub['title']=='PC站_PC' && strpos($_SESSION['account']['noshow_app'],';pc;') !== false){
				unset($menu['child'][$key2]);
				continue;
			}
			if(strpos($sub['title'],'APP打包')!== false && strpos($_SESSION['account']['noshow_app'],';pc;') !== false){
				unset($menu['child'][$key2]);
				continue;
			}
			foreach($sub['child'] as $key3=>&$row){
				if($row['hide']){
					unset($sub['child'][$key3]);
					continue;
				}
				if(is_array($row['url']) && !check_permission($row['url']['plugin'],$row['url']['action'],$row['url']['op'])){
					unset($sub['child'][$key3]);
					continue;
				}
				$menu['url2']=$menu['url2']?:$row['url'];
			}
			if(!$sub['child']){
				unset($menu['child'][$key2]);
			}
		}
		$check1=check_permission($menu['url']['plugin'],$menu['url']['action'],$menu['url']['op']);
		if(!$menu['child'] && (!$menu['url'] || !$check1)){
			unset($framess[$key1]);
		}elseif(!$check1 && $menu['url']){
			$menu['url']=$menu['url2'];
		}
	}
	$framess=array_values($framess);
	//顶部导航右侧菜单组
	$top_right_menu=array();
	//开发中心菜单
	if($_SESSION['isfounder']){
		$developer=array(
			'title'=>'开发_Development center',
			//'url'=>array('plugin'=>'core','action'=>'cloud.developer','title'=>'开发者资料管理'),
			'child'=>array(
				array(
					'title'=>'开发者_developer',
					'child'=>array(
						array('title'=>'开发者资料管理','url'=>'core/cloud.developer/'),
						array('title'=>'应用市场设置','url'=>'core/app_release.myshop.setting/'),
						array('title'=>'客户购买记录','url'=>'core/app_release.myshop.trade/'),
						array('title'=>'我的应用市场','url'=>'core/app_release.myshop.index/'),
					),
				),
				array(
					'title'=>'应用发布',
					'child'=>array(
						array('title'=>'功能插件','url'=>'core/app_release.plugin/'),
						array('title'=>'代销插件','url'=>'core/app_release.authapps/'),
						array('title'=>'微信小程序','url'=>'core/app_release.wxapp/'),
						array('title'=>'支付宝小程序','url'=>'core/app_release.aliapp/'),
						array('title'=>'手机站模版','url'=>'core/app_release.mobile_template/list'),
						array('title'=>'PC站DIY模版','url'=>'core/app_release.pc_template/list'),
						array('title'=>'PC应用模版','url'=>'core/app_release.addons_temp_pc/'),
						array('title'=>'小程序模版','url'=>'core/app_release.wxapp_template/list'),
						array('title'=>'手机站页面组件','url'=>'core/app_release.mobile_blocks/'),
						array('title'=>'pc站页面组件','url'=>'core/app_release.pc_blocks/'),
						array('title'=>'H5互动小游戏','url'=>'core/app_release.h5game/'),
						array('title'=>'系统后台模版','url'=>'core/app_release.manage_template/'),
					),
				),
				array(
					'title'=>'应用开发',
					'child'=>array(
						array('title'=>'原生插件开发','url'=>'core/app_develop.plugin/'),
						array('title'=>'兼容插件开发','url'=>'core/app_develop.old_plugin/'),
						array('title'=>'pc页面组件','url'=>'core/app_develop.blocks.pc/'),
						array('title'=>'手机页面组件','url'=>'core/app_develop.blocks.mobile/'),
						array('title'=>'H5互动小游戏','url'=>'core/app_develop.h5game/'),
						array('title'=>'小程序一键转换','url'=>'core/app_develop.appchange/'),
					),
				),
			),
		);
		$develop_plugins=pdo_getall('core_plugins',array('hide'=>1),array('name','title'));
		if($develop_plugins){
			$menu1=array('title'=>'待开发插件','child'=>array());
			foreach($develop_plugins as $develop_plugin){
				$menu1['child'][]=array('url'=>array('plugin'=>$develop_plugin['name'],'action'=>'basic.module_home'),'title'=>$develop_plugin['title']);
			}
			$developer['child'][]=$menu1;
		}
		$top_right_menu[]=$developer;
	}elseif($_SESSION['user']['type']==3){
		//主管员显示代理加盟
		$agent_setting=core_setting('agent');
		if($agent_setting['open']){
			$agent_menu=array(
				'title'=>'代理加盟',
				'url'=>array('plugin'=>'core','action'=>'agent.add','title'=>'开发者资料管理'),
				'child'=>array(
					array(
						'title'=>'代理加盟',
						'child'=>array(
							array('title'=>'加盟信息','url'=>'core/agent.add/'),
							array('title'=>'收款设置','url'=>'core/agent.agent_setting/'),
							array('title'=>'邀请用户列表','url'=>'core/agent.agent_user/'),
							array('title'=>'我的佣金','url'=>'core/agent.agent_commission/'),
							array('title'=>'我的结算','url'=>'core/agent.agent_clear/'),
						),
					),
				),
			);
			$top_right_menu[]=$agent_menu;
		}
	}
	if($_AR['system']['istakeover'] && $_AR['system']['takeoverplugin']){
		$main_data['top_right_menu']=array();
		$main_data['istakeover']=1;
		$main_data['welcomeaction']=$_AR['system']['takeoverplugin'].'/index/';
		$main_data['homewelcomeaction']=$_AR['system']['takeoverplugin'].'/index/';
	}else{
		$main_data['top_right_menu']=$top_right_menu;
		$main_data['welcomeaction']='core/account.welcome/';
		$main_data['homewelcomeaction']='core/home.welcome/';
	}
	$main_data['key1']=$key11;
	//如果访问的是插件页面，默认显示扩展功能菜单栏
	if($access['plugin']!='core'){
		$plugin=pdo_get('core_plugins',array('name'=>$access['plugin']),array('type','is_legao'));
		$main_data['key1']=4;
		foreach($framess as $fv){
			if($fv['legao_app']==1){
				$legao_app=$fv;
			}
			if($fv['other_app']==1){
				$other_app=$fv;
			}
		}
		if($plugin['is_legao']){
			$main_data['frames']=$legao_app;
		}else{
			$main_data['frames']=$other_app;
		}
	}
	if($_AR['system']['istakeover'] && $_AR['system']['takeoverplugin']){
		$main_data['framess']=cfc($_AR['system']['takeoverplugin'])->getmenus();
	}else{
		$main_data['framess']=$framess;
	}
}elseif($_AR['system']['istakeover'] && $_AR['system']['takeoverplugin']){
	$main_data['istakeover']=1;
}
if(!$main_data['name']){
	$main_data['name']=$_AR['page']['name'];
}
if(!$main_data['title']){
	$main_data['title']=$_AR['page']['title'];
}
if(!$main_data['icon']){
	$main_data['icon']=$_AR['page']['icon'];
}
if(!$main_data['mglogo']){
	$main_data['mglogo']=$_AR['page']['mglogo'];
}
if(!$main_data['logo']){
	$main_data['logo']=$_AR['page']['logo'];
}
if(!$main_data['llogo']){
	$main_data['llogo']=$_AR['page']['llogo'];
}
if(!$main_data['js_supportimg']){
	$main_data['js_supportimg']=$_AR['page']['js_supportimg'];
}
if(!$main_data['js_support']){
	$main_data['js_support']=$_AR['page']['js_support'];
}
if(!$main_data['kflink']){
	$main_data['kflink']=$_AR['page']['kflink'];
	if(strpos($main_data['kflink'],'jy_kefu')!==false || strpos($main_data['kflink'],'index.php?')!==false){
		$main_data['kflink']=$main_data['kflink'].'&fromh5wxapp='.$_SESSION['fromh5wxapp'];
	}
}
if(!$main_data['alipay']){
	$main_data['alipay']=$_AR['page']['alipay'];
}
if(!$main_data['wxpay']){
	$main_data['wxpay']=$_AR['page']['wxpay'];
}
if(!$main_data['ewm']){
	$main_data['ewm']=$_AR['page']['ewm'];
}
if(!$main_data['kfewm']){
	$main_data['kfewm']=$_AR['page']['kfewm'];
}
if(!$main_data['phone']){
	$main_data['phone']=$_AR['page']['phone'];
}
if(!$main_data['qq']){
	$main_data['qq']=$_AR['page']['qq'];
}
if(!$main_data['footerright']){
	$main_data['footerright']=$_AR['page']['footerright'];
}
if(!$main_data['footerleft']){
	$main_data['footerleft']=$_AR['page']['footerleft'];
}
if(!$main_data['syscolor']){
	$main_data['syscolor']=$_AR['page']['syscolor']?$_AR['page']['syscolor']:'#18bc9c';
}
if(!$main_data['hovercolor']){
	$main_data['hovercolor']=$_AR['page']['hovercolor']?$_AR['page']['hovercolor']:'#15a589';
}
if(!$main_data['statuscolor']){
	$main_data['statuscolor']=$_AR['page']['statuscolor']?$_AR['page']['statuscolor']:'#f60';
}
if(!$main_data['closed_kefu']){
	$main_data['closed_kefu']=$_AR['page']['closed_kefu'];
}
if(!$main_data['closed_kefublock']){
	$main_data['closed_kefublock']=$_AR['page']['closed_kefublock'];
}
if(!$main_data['closed_shouce']){
	$main_data['closed_shouce']=$_AR['page']['closed_shouce'];
}
if(!$main_data['closed_mkefu']){
	$main_data['closed_mkefu']=$_AR['page']['closed_mkefu'];
}
if(!$main_data['closed_alipay']){
	$main_data['closed_alipay']=$_AR['page']['closed_alipay'];
}
if(!$main_data['closed_wxpay']){
	$main_data['closed_wxpay']=$_AR['page']['closed_wxpay'];
}
if(!$main_data['closed_alipay']){
	$main_data['closed_alipay']=$_AR['page']['closed_alipay'];
}
if(!$main_data['closed_ewm']){
	$main_data['closed_ewm']=$_AR['page']['closed_ewm'];
}
if(!$main_data['closed_phone']){
	$main_data['closed_phone']=$_AR['page']['closed_phone'];
}
if(!$main_data['closed_angleup']){
	$main_data['closed_angleup']=$_AR['page']['closed_angleup'];
}
if(!$main_data['closed_feedback']){
	$main_data['closed_feedback']=$_AR['page']['closed_feedback'];
}
if(!$main_data['lbg']){
	$main_data['lbg']=$_AR['page']['lbg'];
}
if(!$main_data['template_mg']){
	$system=core_setting('system');
	$main_data['template_mg']=$system['template_mg']?:'default';
}
if(!$main_data['openbackpage']){
	$main_data['openbackpage']=$_AR['page']['openbackpage'];
}
//获取custom主题颜色
$accsyscolor=pdo_getcolumn('core_accounts',array('uniacid'=>$_SESSION['uniacid']),'syscolor');
if(intval($_RQ['link_webid'])){
	$customsyscolor=pdo_getcolumn('core_mobile_web',array('id'=>intval($_RQ['link_webid']),'uniacid'=>$_SESSION['uniacid']),'syscolor');
}elseif($main_data['syscolor']){
	$customsyscolor=$main_data['syscolor'];
}elseif($accsyscolor){
	$customsyscolor=$accsyscolor;
}else{
	$customsyscolor='';
}
$_SESSION['customsyscolor']=$customsyscolor;
$main_data['customsyscolor']=$customsyscolor;
$main_data['show_lang']=$_SESSION['show_lang']?:'ch';
$search=html_config($access,$main_data);
$search['page']=$_AR['page'];
$search['isfounder']=$_SESSION['isfounder'];
if($_SESSION['uid']){
	$search['username']=$_SESSION['user']['name'];
}else{
	$search['username']=false;
}
//JSSDK
if ($_SESSION['wechat_id']){
	
	$search['jssdk']=cfc('account',$_SESSION['wechat_id'])->getJssdkConfig();
	$search['jssdk']=json_encode($search['jssdk']);
	$share=array(
			'title'=>$_AR['page']['title'],
			'desc'=>$_AR['page']['description'] ? $_AR['page']['description'] : $_AR['page']['title'],
			'link'=>$_AR['siteurl'],
			'imgUrl'=>$_AR['page']['logo'] ? SITEROOT.'resource/'.$_AR['page']['logo'] : SITEROOT.'core/resource/images/nopic.jpg',
	);
	$search['share']=ijson_encode($share);
}else{
	$search['jssdk']='{}';
	$search['share']='{}';
}
if($_RQ['text_main']){
	$mainsource=ROOT_D . "/{$_SESSION['this']}/templates/default/{$_SESSION['os']}/common/main2.html";
}else{
	$mainsource=ROOT_D . "/{$_SESSION['this']}/templates/{$_AR['system']['template_name']}/{$_SESSION['os']}/common/main.html";
}

if(!is_file($mainsource)){
	$mainsource = ROOT_D . "/{$_SESSION['this']}/templates/default/{$_SESSION['os']}/common/main.html";
	if(in_array($_SESSION['os'],array('baiduapp','aliapp','ttapp','wxapp'))){
		$mainsource=ROOT_D . "/{$_SESSION['this']}/templates/default/mobile/common/main.html";
	}
}
if(!is_file($mainsource)){
	$mainsource = ROOT_D . "/{$_SESSION['this']}/templates/default/windows/common/main.html";
}
if(!is_file($mainsource)){
	$mainsource = ROOT_D . "/{$_SESSION['this']}/templates/default/mobile/common/main.html";
}
if(!is_file($mainsource)){
	exit('error:template source needed is not exist!');
}
$html=file_get_contents($mainsource);
$html=cfc('tools')->replace($search,$html);
echo $html;
//access_log();
exit;
?>